package com.zhoun.controller.portal;

import com.zhoun.common.Const;
import com.zhoun.common.ServerResponse;
import com.zhoun.pojo.User;
import com.zhoun.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/selectProductBySpec")
    @ResponseBody
    public ServerResponse selectProductBySpec(String spec, HttpSession session){
        User user = (User) session.getAttribute(Const.CURRENT_USER);
        if (user == null){
            return ServerResponse.createByErrorMessage("用户未登录，请登录后查询");
        }
        return productService.selectProductBySpec(spec);
    }

    @RequestMapping("/getProductListByCategoryId")
    @ResponseBody
    public ServerResponse getProductListByCategoryId(Integer categoryId,HttpSession session){
        User user = (User) session.getAttribute(Const.CURRENT_USER);
        if (user == null){
            return ServerResponse.createByErrorMessage("用户未登录，请登录后查询");
        }
        return productService.getProductListByCategoryId(categoryId);
    }

}
